<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
</html>
<script>
  //基于冒泡

  // var moveZeroes = function(nums) {
  //   for (let i = 0; i < nums.length; i++) {
  //     for (let j = 0; j < nums.length-i-1; j++) {
  //       if(nums[j] === 0){
  //         [nums[j],nums[j+1]] = [nums[j+1],nums[j]];
  //       }
  //     }
  //   }
  // };

  //双指针
  var moveZeroes = function(nums) {
    let left = 0;
    let right = 0;
    for(right;right<nums.length;right++){
      if(nums[right]!==0){
        nums[left] = nums[right];
        left++;
      }
    }
    for(left;left<nums.length;left++){
      nums[left] = 0
    }
  };
  let nums = [0,1,0,3,12];
  moveZeroes(nums)
  console.log(nums);
</script>